package mulMan.gui.view;

import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import mulMan.domain.AudioFile;
import mulMan.domain.Library;

public class LibraryView extends JFrame{

	
	private static final long serialVersionUID = 2673316415973781084L;

	private Library library;
	private JList<AudioFile> listOfAudioFiles;
	private JButton buttonNew;
	private JButton buttonDelete;
	
	public Library getLibrary() {
		return library;
	}
	public void setLibrary(Library library) {
		this.library = library;
	}
	public JList<AudioFile> getListOfAudioFiles() {
		return listOfAudioFiles;
	}
	public void setListOfAudioFiles(JList<AudioFile> listOfAudioFiles) {
		this.listOfAudioFiles = listOfAudioFiles;
	}
	
	
	public LibraryView(Library library){
		this.library = library;
		
		initView();
	    initFields();
	}
	
	private void initFields() {
	}
	
	private void initView() {
		JPanel panel = new JPanel();
	    getContentPane().add(panel);
	    panel.setLayout(null);
	       
		setTitle("Library window");
	    setSize(300, 200);
	    setLocationRelativeTo(null);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    setVisible(true);
	    
	    JLabel label1 = new JLabel();
	    label1.setText("List of MP3 Audio Files: ");
	    label1.setBounds(0, 0, 200, 20);
	    panel.add(label1);

	    listOfAudioFiles = new JList<AudioFile>(library);
	    listOfAudioFiles.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
	    listOfAudioFiles.setLayoutOrientation(JList.VERTICAL);
	    listOfAudioFiles.setVisibleRowCount(4);
	    
	    JScrollPane listScroller = new JScrollPane(listOfAudioFiles);
	    listScroller.setPreferredSize(new Dimension(250, 80));
	    listScroller.setBounds(0, 30, 270, 90);
	    panel.add(listScroller);
	    
	    buttonNew = new JButton();
	    buttonNew.setText("Add");
	    buttonNew.setBounds(15, 130, 100, 20);
	    panel.add(buttonNew);
	    
	    buttonDelete = new JButton();
	    buttonDelete.setText("Delete");
	    buttonDelete.setBounds(125, 130, 100, 20);
	    panel.add(buttonDelete);
	}
	
	public void addModifyAudioFileListener(MouseListener mafl) {
		listOfAudioFiles.addMouseListener(mafl);
    }
	
	public void addNewAudioFileListener(ActionListener nafl) {
		buttonNew.addActionListener(nafl);
    }
	
	public void addDeleteAudioFileListener(ActionListener dafl) {
		buttonDelete.addActionListener(dafl);
    }
}
